//
//  Jurisdication.swift
//  BridgeHousePeople
//  检查权限
//  Created by 松松 on 2018/6/19.
//  Copyright © 2018年 ZRQ. All rights reserved.
//

import Foundation
import AVFoundation
import UserNotifications

open class Jurisdication {

    //MARK:检查是否有麦克风权限
    public class func checkRecord(success:@escaping ()->Void){
        let videwStatu = AVCaptureDevice.authorizationStatus(for: .audio)
        if videwStatu == AVAuthorizationStatus.notDetermined{
            let avadioSession = AVAudioSession.sharedInstance()
            avadioSession.requestRecordPermission { (ok) in
                if ok{
                    success()
                }else{
                    ssPrint("用户未授权")
                }
            }
        }else if videwStatu == AVAuthorizationStatus.restricted || videwStatu == AVAuthorizationStatus.denied{
            Toast.showMessage("未开启麦克风权限")
        }else{
            ssPrint("已开启麦克风权限")
        }
    }

    //MARK:获取通知权限
    public class func checkNotification(succeww:@escaping ()->Void){

        if #available(iOS 10.0, *) {
            UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .sound, .alert, .carPlay]) { (success, error) in
                ssPrint("授权" + (success ? "成功" : "失败"))
                if success{
                    succeww()
                }else{
                    ssPrint("获取通知授权失败")
                }
            }
        } else {
            let settings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
            UIApplication.shared.registerUserNotificationSettings(settings)
            succeww()
        }

        let setting = UIApplication.shared.currentUserNotificationSettings
        if setting == nil{
            
        }else{
            
        }
    }

}
